package tum0r.model;

import tum0r.sql.MySQL;

import java.util.LinkedList;

/**
 * 工程: ResourcesDatabase<br>
 * 包: tum0r.model<br>
 * 创建者: tum0r<br>
 * 创建时间: 2020/10/4 13:13<br>
 * <br>
 */
public class StaticResource {
    public static MySQL sql = new MySQL();

    // 数据库名
    public static String DATABASE_NAME = "FileShare";
    public static String FILE_INFORMATION_TABLE = "T_FileInformation";
    public static String FILE_CONTENT_TABLE = "T_FileContent";
    public static String FILE_RELATE_TABLE = "T_FileRelate";

    public static String[] INNIT_DATABASE = new String[]{
            // 创建数据库
            "CREATE DATABASE IF NOT EXISTS " + DATABASE_NAME + ";",
            // 创建文件信息表
            "CREATE TABLE IF NOT EXISTS " + FILE_INFORMATION_TABLE + "(ID CHAR(64) NOT NULL, Name TEXT NOT NULL, Type TEXT NOT NULL, Label LONGTEXT, CreateTime DATETIME, LastAccessTime DATETIME, Size BIGINT);",
            // 创建文件信息表主键和索引
            "ALTER TABLE " + FILE_INFORMATION_TABLE + " ADD PRIMARY KEY ID(ID(64));",
            "ALTER TABLE " + FILE_INFORMATION_TABLE + " ADD INDEX `Name`(Name(512));",
            "ALTER TABLE " + FILE_INFORMATION_TABLE + " ADD INDEX Type(Type(512));",
            "ALTER TABLE " + FILE_INFORMATION_TABLE + " ADD INDEX Label(Label(512));",
            "ALTER TABLE " + FILE_INFORMATION_TABLE + " ADD INDEX CreateTime(CreateTime);",
            "ALTER TABLE " + FILE_INFORMATION_TABLE + " ADD INDEX LastAccessTime(LastAccessTime);",
            "ALTER TABLE " + FILE_INFORMATION_TABLE + " ADD INDEX Size(Size);",
            // 创建文件内容表
            "CREATE TABLE IF NOT EXISTS " + FILE_CONTENT_TABLE + "(ID CHAR(64) NOT NULL, Fingerprint TEXT NOT NULL, Content LONGBLOB NOT NULL);",
            // 创建文件内容表主键和索引
            "ALTER TABLE " + FILE_CONTENT_TABLE + " ADD PRIMARY KEY ID(ID(64));",
            "ALTER TABLE " + FILE_CONTENT_TABLE + " ADD INDEX Fingerprint(Fingerprint(512));",
            // 创建文件信息和文件内容关联表
            "CREATE TABLE IF NOT EXISTS " + FILE_RELATE_TABLE + "(ID CHAR(64) NOT NULL, Sequence INT NOT NULL, FileInformationID CHAR(64) NOT NULL, FileContentID CHAR(64) NOT NULL, FOREIGN KEY FileInformationID(FileInformationID) REFERENCES " + FILE_INFORMATION_TABLE + "(ID), FOREIGN KEY FileContentID(FileContentID) REFERENCES " + FILE_CONTENT_TABLE + "(ID));",
            // 创建文件信息和文件内容关联表主键
            "ALTER TABLE " + FILE_RELATE_TABLE + " ADD PRIMARY KEY ID(ID(64));"
    };

    public static final String LABEL_FILE = "文件:";
    public static final String LABEL_MARK = "标签:";

    public static final int FILE_MAX_SIZE = 1024 * 1024 * 1024;

    public static LinkedList<Object> COMMAND = new LinkedList<>();
}
